package com.briup.corejava.day19;


import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * 使用转换流读取GBK编码的文件内容
 * InputStreamReader
 * OutputStreamWriter
 */
public class Test5 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        InputStreamReader isr = null;
        FileOutputStream fos = null;
        OutputStreamWriter osw = null;

        try {
            fis = new FileInputStream("src/com/briup/corejava/day19/file/gbk.txt");
            isr = new InputStreamReader(fis,"gbk");
            fos = new FileOutputStream("src/com/briup/corejava/day19/file/utf8.txt");
            osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
            char[] c = new char[1024];
            int len = -1;
            while((len = isr.read(c))!=-1){
                // 输出到控制台
                System.out.println(new String(c,0,len));
                // 输出到utf8.txt文件
                osw.write(c,0,len);
                osw.flush();
            }

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
